package com.s4j.core.manager.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name="S4J_SYSMODULE")
public class SysModule {

	/*
	 * 模块主键
	 */
	private Long moduleId;
	
	/*
	 * 模块编号,非空
	 */
	private String moduleNo;
	
	/*
	 * 模块名称,非空
	 */
	private String moduleName;
	
	/*
	 * 模块主页,非空
	 */
	private String homePage;
	
	/*
	 * 排序号,非空
	 */
	private Integer sortNum;
	
	/*
	 * 层级,非空
	 */
	private Short level;
	
	/*
	 * 是否叶子节点，非空
	 */
	private Short isLeaf;
	
	/*
	 * 子节点列表
	 */
	private List<SysModule> children;

	/*
	 * 父节点
	 */
	private SysModule parent;
	
	/*
	 * 对应的SYSPROJECT
	 */
	private SysProject project;
	
	private List<SysMenu> menus;
	
	/*
	 * 模块打开时初始化的listener
	 */
	private String moduleInitListener;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getModuleId() {
		return moduleId;
	}

	public void setModuleId(Long moduleId) {
		this.moduleId = moduleId;
	}

	@Column(length=50, nullable=false, unique=true)
	public String getModuleNo() {
		return moduleNo;
	}

	public void setModuleNo(String moduleNo) {
		this.moduleNo = moduleNo;
	}

	@Column(length=50, nullable=false)
	public String getModuleName() {
		return moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}

	@Column(length=100, nullable=false)
	public String getHomePage() {
		return homePage;
	}

	public void setHomePage(String homePage) {
		this.homePage = homePage;
	}

	@Column(precision=5, scale=0, nullable=false)
	public Integer getSortNum() {
		return sortNum;
	}

	public void setSortNum(Integer sortNum) {
		this.sortNum = sortNum;
	}

	@Column(precision=2, scale=0, nullable=false)
	public Short getLevel() {
		return level;
	}

	public void setLevel(Short level) {
		this.level = level;
	}

	@Column(precision=1, scale=0, nullable=false)
	public Short getIsLeaf() {
		return isLeaf;
	}

	public void setIsLeaf(Short isLeaf) {
		this.isLeaf = isLeaf;
	}

	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="parent")
	public List<SysModule> getChildren() {
		return children;
	}

	public void setChildren(List<SysModule> children) {
		this.children = children;
	}

	@ManyToOne(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
	@JoinColumn(name="parentId")
	public SysModule getParent() {
		return parent;
	}

	public void setParent(SysModule parent) {
		this.parent = parent;
	}
	
	@OneToOne  
    @JoinColumn(name="projectId",insertable=true,unique=true)
	public SysProject getProject() {
		return project;
	}

	public void setProject(SysProject project) {
		this.project = project;
	}

	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="module")
	public List<SysMenu> getMenus() {
		return menus;
	}

	public void setMenus(List<SysMenu> menus) {
		this.menus = menus;
	}

	@Column(length=100, nullable=true)
	public String getModuleInitListener() {
		return moduleInitListener;
	}

	public void setModuleInitListener(String moduleInitListener) {
		this.moduleInitListener = moduleInitListener;
	}
}
